/*
 * @Descripttion:
 * @version:
 * @Author: sueRimn
 * @Date: 2020-10-20 17:48:29
 * @LastEditors: sueRimn
 * @LastEditTime: 2020-11-16 16:33:37
 */
import Vue from 'vue'

import 'normalize.css/normalize.css' // A modern alternative to CSS resets

import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'

import '@/styles/index.scss' // global css
import './styles/theme/index.css'
import '../public/UEditor/themes/default/css/ueditor.css'
import App from './App'
import store from './store'
import router from './router'

import '@/icons' // icon
import '@/permission' // permission control

Vue.use(ElementUI)
Vue.config.productionTip = false

// v-pageRoles="['aa']" //调用
Vue.directive('pageRoles', {
    bind: function(el, binding, vnode) {
        let permissionList = binding.value// 在页面上绑定的 对应权限显示
        var roles = store.getters.pageRoles// 获取的用户权限

        if (roles.includes('*')) {
            return
        }
        if (roles.length == 0) {
            el.style.display = 'none'
            return
        }
        if (!roles.includes(permissionList[0])) {
            el.style.display = 'none'
        }
        // for (var i = 0; i <= roles.length; i++) {
        //     console.log('权限', permissionList.includes(roles[i]), permissionList, roles[i])
        //     if (!permissionList.includes(roles[i])) {
        //         el.style.display = 'none'
        //     }
        // }
    }
})

Vue.directive('noRolesTips', {
    bind: function(el, binding, vnode) {
        let permissionList = binding.value// 在页面上绑定的 对应权限显示
        var roles = store.getters.pageRoles// 获取的用户权限

        if (roles.includes('*')) {
            el.style.display = 'none'
            return
        }
        if (roles.length == 0) {
            el.style.display = 'block'
            return
        }
        if (!roles.includes(permissionList[0])) {
            el.style.display = 'block'
        } else {
            el.style.display = 'none'
        }
    }
})

new Vue({
    el: '#app',
    router,
    store,
    render: h => h(App)
})
